﻿@model Bricks.Business.Models.Account.RoleInfo

@{
    ViewBag.Title = "权限组授权";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        //当页面首次刷新的时候执行的事件
        initRoleList();
        //载入嵌入页面（权限页面）
        $.LoadEmbed('#purviewUIEmbed', '/Purview/Purview');
    });
    //实现对DataGird控件的绑定操作

    function initRoleList(queryData) {
        $('#selectedRoleDataGrid').datagrid({
            url: '/Purview/GetSelectedRoleList?RoleID=' + $("#hSelectedRoleID").val(),
            nowrap: true,
            autoRowHeight: false,
            singleSelect: true,
            striped: true,
            collapsible: true,
            pagination: false,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            queryParams: queryData,  //异步查询的参数
            toolbar: '#selectedRoleToolBar',
            columns: [[
                { title: '@Html.LabelFor(model => model.RoleName)', field: 'RoleName', width: 165, sortable: false },
            ]],
            onClickRow: function (index, row) {
                //以下方法可行
                var selectedRow = $("#selectedRoleDataGrid").datagrid("getSelected");
                if (selectedRow) {
                    $('#purviewDataGrid').datagrid('load', { instanceID: selectedRow.ID, configType: 'RolePurview' });
                }
                //$.EasyuiSlide("点击事件测试");
            }
        });
    }
    var RolePurview = {
        //选择权限组
        ChooseRole: function () {
            //var orgList = $('#selectedRoleDataGrid').datagrid('getRows');  //获取列表数据
            ////var orgListJson = JSON.stringify(orgList);  //转为json格式
            //var roleIDs = "";
            //if (orgList.length > 0) {
            //    for (var i = 0; i < orgList.length; i++) {
            //        if (roleIDs.length == 0)
            //            roleIDs = orgList[i].ID;
            //        else
            //            roleIDs = roleIDs + "," + orgList[i].ID;
            //    }
            //}
            //RolePurview.Mutual("选择权限组", "/Purview/ChooseRole?roleIDs=" + roleIDs);  //弹出对话框

            $.EasyuiMsg("暂不支持批量进行权限组授权");
        },

        //实体操作
        Mutual: function (title, href) {
            $.ModelDialog({
                title: title, href: href, width: 320, maximizable: true,
                handler: function () {
                    $.ModelForm({
                        validate: true, button: $(this),
                        id: "#form-chooseOrg",
                        //url: "/Purview/ChooseOrgPost?selectedOrgIDs=" + $("#hRoleIDs").val(),  //eg：Purview/ChooseRole
                        url: "/Purview/ChooseOrgPost",  //eg：Purview/ChooseRole
                        success: function (result) {
                            //debugger;
                            var roleIDs = $("#hRoleIDs").val();
                            //RolePurview.Reload();
                            //$.EasyuiMsg(roleIDs);
                            //document.getElementById("hSelectedRoleID").value = roleIDs;  //给隐藏域字段赋值
                            //RolePurview.Reload();
                            $("#selectedRoleDataGrid").datagrid("reload", { roleID: roleIDs });  //刷新左边权限组列表
                            $("#purviewDataGrid").datagrid("reload");  //刷新右边权限路径列表（实际运行疑问：为什么这个语句在下方，而却先执行呢？）
                        }
                    });
                },
                onLoad: function () { RolePurview.FormInit(); }
            });
        },

        //刷新重载
        Reload: function () {
            $("#selectedRoleDataGrid").datagrid("reload");
        },

        //弹窗初始化
        FormInit: function () {
        }
    }
</script>

<table>
    <tr>
        <form id="form-rolePurview" method="post">
            <td>
                <div region="west" data-options="border:false" style="width: 200px; height: 387px;">
                    <div class="easyui-panel" title="权限组选择">
                        <!--已选权限组列表-->
                        <table id="selectedRoleDataGrid" style="height: 358px;"></table>
                        <!--已选权限组工具栏-->
                        <div id="selectedRoleToolBar">
                            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='RolePurview.ChooseRole()' data-options='plain:true,iconCls:"icon-application_lightning"'>选择权限组</a>
                        </div>
                    </div>
                </div>
            </td>

            <!--右边为权限组数表，可勾选用户所属权限组和勾选对应权限-->
            <td>
                @*<div region="center" style="border-left: 0px; width: 420px; height: 387px;">
                    <div class="easyui-panel" title="权限组授权">
                        @Html.Raw(ViewBag.PurviewUI)
                    </div>
                </div>*@

                <div region="center" style="border-left: 0px; width: 420px; height: 387px;">
                    <div id="purviewUIEmbed" class="easyui-panel" fit="true"></div>
                </div>
            </td>
        </form>
    </tr>
</table>

<input type="hidden" id="hSelectedRoleID" value="@ViewBag.SelectedRoleID" />
<input type="hidden" id="hConfigType" value="@ViewBag.ConfigType" />
